<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/jquery/dist/jquery.js"></script>
</head>

<body>
    <button id="btn">点击获取信息</button>
    <script>
        $('#btn').click(function(e) {
            e.preventDefault()
                // 1.创建xhr对象
            var xhr = new XMLHttpRequest();
            // 2.调用open方法
            xhr.open('GET', 'http://www.liulongbin.top:3006/api/getbooks');
            // 3.调用send方法请求数据
            xhr.send();
            // 4.监听数据
            xhr.onreadystatechange = function() {
                if (xhr.readystate === 4 && xhr.status === 200) {
                    console.log(xhr.responseText);

                }
            }
        })
    </script>
</body>

</html>